import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JTextPane;

public class Menu extends JDialog {

	private JTextField textField;
	private JTextPane top;
	private JTextPane back;
	private Deque<String> deque = new Deque<String>();

	private JButton clearB = new JButton("clear");
	private JButton pushEnd = new JButton("pushEnd");
	private JButton pushStart = new JButton("pushStart");
	private JButton popEnd = new JButton("popEnd");
	private JButton popStart = new JButton("popStart");

	/**
	 * Launch the application.
	 */

	public static void main(String[] args) {
		try {
			Menu dialog = new Menu();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setTitle("Deque");
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public Menu() {
		setBounds(100, 100, 450, 300);
		BorderLayout borderLayout = new BorderLayout();
		borderLayout.setVgap(75);
		getContentPane().setLayout(borderLayout);
		{
			JPanel inputTextPane = new JPanel();
			inputTextPane.setLayout(new FlowLayout(FlowLayout.LEFT));
			getContentPane().add(inputTextPane, BorderLayout.WEST);
			textField = new JTextField();
			inputTextPane.add(textField);
			textField.setColumns(10);
		}
		{
			top = new JTextPane();
			top.setEditable(false);
			getContentPane().add(top, BorderLayout.NORTH);
		}
		{
			back = new JTextPane();
			back.setEditable(false);
			getContentPane().add(back, BorderLayout.SOUTH);
		}
		{
			JPanel buttonsBlock = new JPanel();
			buttonsBlock.setLayout(new FlowLayout(FlowLayout.LEFT));
			getContentPane().add(buttonsBlock, BorderLayout.CENTER);
			buttonsBlock.add(pushEnd);
			buttonsBlock.add(pushStart);
			buttonsBlock.add(clearB);
			buttonsBlock.add(popEnd);
			buttonsBlock.add(popStart);
		}
		pushEnd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String input;
				input = textField.getText();
				deque.pushEnd(input);
				textField.setText("");
				top.setText(deque.showTop());
				back.setText(deque.showEnd());
			}
		});
		popEnd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String input;
				input = deque.popEnd();
				textField.setText(input);
				top.setText(deque.showTop());
				back.setText(deque.showEnd());
			}
		});
		pushStart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String input;
				input = textField.getText();
				deque.pushTop(input);
				textField.setText("");
				top.setText(deque.showTop());
				back.setText(deque.showEnd());
			}
		});
		popStart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String input;
				input = deque.popTop();
				textField.setText(input);
				top.setText(deque.showTop());
				back.setText(deque.showEnd());
			}
		});
		clearB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				textField.setText("");
			}
		});
	}
}
